import React from 'react'
import {
    Form,
    Input,
    Button,
} from 'antd-mobile'
import axios from 'axios';
import { useNavigate } from 'react-router-dom';
function Login() {
    const nav = useNavigate()
    const onFinish = (values) => {
        console.log(values);
        axios.post('/api/login', values).then((res) => {
            console.log(res);
            if (res.data.code == 200) {
                nav('/')
                localStorage.setItem('token', res.data.data.token)

            }

        })

    }
    return (
        <div>
            <Form
                name='form'
                onFinish={onFinish}

            >

                <Form.Item
                    name='username'
                    label='用户名'
                    rules={[{ required: true, message: '姓名不能为空' }]}
                >
                    <Input onChange={console.log} placeholder='请输入姓名' />
                </Form.Item>

                <Form.Item
                    name='password'
                    label='密码'
                    rules={[{ required: true, message: '姓名不能为空' }]}
                >
                    <Input onChange={console.log} placeholder='请输入密码' />
                </Form.Item>
                <Button block type='submit' color='primary' size='large'>
                    提交
                </Button>

            </Form>
        </div>
    )
}

export default Login